package Offer2018;

/**
 * Created by 雷文康 on 2018/3/3.
 */
public class Test12 {
    public static void main(String[] args) {
        print1ToN(3);
    }

    public static void print1ToN(int n) {
        if (n <= 0) {
            return;
        }
        int[] array = new int[n];
        //初始化
        for (int i = 0; i < n; i++) {
            array[i] = 0;
        }
        while (add(array)) {
            print(array);
        }
    }

    private static boolean add(int[] array) {
        int takeOver = 0;
        for (int i = array.length - 1; i >= 0 ; i--) {
            int sum = array[i] + takeOver;
            if (i == array.length - 1) {
                sum++;
            }
            if (sum == 10) {
                if (i == 0) {
                    return false;
                } else {
                    array[i] = 0;
                    takeOver = 1;
                }
            } else {
                array[i] = sum;
                break;
            }
        }
        return true;
    }

    private static void print(int[] array) {
        boolean flag = false;
        for (int i = 0; i < array.length; i++) {
            if (array[i] != 0) {
                flag = true;
            }
            if (flag) {
                System.out.print(array[i]);
            }
        }
        System.out.print(" ");
    }
}
